package com.wk.code.wkserver.controller.admin;

import com.wk.code.wkserver.controller.common.BaseController;
import com.wk.code.wkserver.controller.common.BaseController;
import com.wk.code.wkserver.request.admin.AdminDemandRequest;
import com.wk.code.wkserver.request.app.DemandVerifyRequest;
import com.wk.code.wkserver.request.base.BasePageRequest;
import com.wk.code.wkserver.request.app.DemandVerifyRequest;
import com.wk.code.wkserver.response.admin.DemandResponse;
import com.wk.code.wkserver.response.base.PageInfo;
import com.wk.code.wkserver.response.result.R;
import com.wk.code.wkserver.service.IDemandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wq
 * @since 2021-08-15
 */
@RestController
@RequestMapping("admin/demand")

@Api(tags = "admin-需求管理")
public class AdminDemandController extends BaseController {

    @Resource
    private IDemandService demandService;


    @ApiOperation(value = "需求分页列表")
    @PostMapping("/page")
    public R<PageInfo<DemandResponse>> page(@RequestBody AdminDemandRequest request) {
        return R.success(demandService.page(getSysUserId(), request));
    }

    /**
     * 需求审核
     *
     * @param request 请求参数
     * @return R
     */
    @ApiOperation(value = "需求审核")
    @PostMapping("/verify")
    public R<Void> verifyDemand(@RequestBody DemandVerifyRequest request) {
        demandService.verifyDemand(getSysUserId(), request);
        return R.success();
    }

    /**
     * 详情
     *
     * @param id ID
     * @return R
     */
    @ApiOperation(value = "详情")
    @GetMapping("/detail")
    public R<DemandResponse> detail(Integer id) {
        return R.success(demandService.detail(id));
    }

    /**
     * 设置下单金额
     *
     * @param demandId 需求ID
     * @param amount   下单金额
     * @return R
     */
    @ApiOperation(value = "设置下单金额")
    @GetMapping("/updateOrderAmount")
    public R<Void> updateOrderAmount(Integer demandId, String amount) {
        demandService.updateOrderAmount(demandId, new BigDecimal(amount));
        return R.success();
    }

    /**
     * 设置已完成
     *
     * @param demandId 需求ID
     * @return R
     */
    @ApiOperation(value = "设置已完成")
    @GetMapping("/updateFinish")
    public R<Void> updateFinish(Integer demandId) {
        demandService.updateFinish(demandId);
        return R.success();
    }

    /**
     * 后台设置为已接单为取消
     *
     * @param demandId 需求订单ID
     * @return R<Void>
     */
    @ApiOperation(value = "后台设置为已接单为取消")
    @GetMapping("/updateDemandCancel")
    public R<Void> updateDemandCancel(Integer demandId) {
        demandService.updateDemandCancel(demandId);
        return R.success();
    }


    /**
     * 后台设置为已接单为取消
     *
     * @param demandId 需求订单ID
     * @return R<Void>
     */
    @ApiOperation(value = "后台删除需求")
    @GetMapping("/deleteDemand")
    public R<Void> deleteDemand(Integer demandId) {
        demandService.deleteDemand(demandId);
        return R.success();
    }

    /**
     * 后台进行中的需求为取消
     *
     * @param demandId 需求订单ID
     * @return R<Void>
     */
    @ApiOperation(value = "后台进行中的需求为取消")
    @GetMapping("/demandOrderCancel")
    public R<Void> demandOrderCancel(Integer demandId) {
        demandService.demandOrderCancel(demandId);
        return R.success();
    }


    /**
     * 设置淘宝订单号
     *
     * @param demandId 需求订单ID
     * @return R<Void>
     */
    @ApiOperation(value = "设置淘宝订单号")
    @GetMapping("/setTbOrder")
    public R<Void> setTbOrder(Integer demandId, String tbOrderNo) {
        demandService.setTbOrder(demandId, tbOrderNo);
        return R.success();
    }


}
